package io.bdmc.modules.bss.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.bdmc.common.annotation.SysLogger1;
import io.bdmc.common.utils.R;
import io.bdmc.common.utils.Constant.ModifyName;
import io.bdmc.modules.bss.entity.DeviceAlarmSetting;
import io.bdmc.modules.bss.service.IDeviceAlarmSettingService;
import io.bdmc.modules.sys.controller.AbstractController;

/**
 * <p>
 * 报警屏蔽设置 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2020-08-11
 */

// "报警屏蔽设置", description = "接口地址：/bss/alarm/setting")
@RestController
@RequestMapping("/bss/alarm/setting")
public class DeviceAlarmSettingController extends AbstractController {

	@Autowired
	IDeviceAlarmSettingService _devicealarmsettingSvs;

	@GetMapping("/list")
	// "分页查询DeviceAlarmSetting", notes = "分页查询报警屏蔽设置")
	@RequiresPermissions("bss:alarm:setting:list")
	public R list(String devName) {
		List<DeviceAlarmSetting> list = _devicealarmsettingSvs
				.list(new QueryWrapper<DeviceAlarmSetting>().eq("dev_name", devName).orderByAsc("order_asc"));
		return R.ok().putData(list);

	}

	@SysLogger1(value = "修改报警屏蔽设置", entityType = DeviceAlarmSetting.class, operationType = ModifyName.UPDATE)
	@PostMapping("/update")
	// "修改报警屏蔽设置", notes = "修改报警屏蔽设置")
	@RequiresPermissions("bss:alarm:setting:update")
	public R update(@RequestBody DeviceAlarmSetting setting) {
		DeviceAlarmSetting dbSetting = _devicealarmsettingSvs.getById(setting.getAlarmSettingId());
		dbSetting.setEnabled(setting.isEnabled());
		Boolean b = dbSetting.updateById();
		return R.trueOrFalse(b);
	}

}
